package com.OnTimeTeam.OnTime;

import android.app.TabActivity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;

@SuppressWarnings("deprecation")
public class ConfirmSmartAlarmTransit  extends TabActivity {
	 
	
	/***Everything that happens within these brackets, happens when the activity is created.
   OnCreate is the first method which opens the application on the user side****/
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       
       this.requestWindowFeature(Window.FEATURE_NO_TITLE);
       
       setContentView(R.layout.show_route_details_tabhost);//set the view of the first screen
       
		/** TabHost will have Tabs */
		final TabHost tabHost = getTabHost();
		
		/** TabSpec used to create a new tab.
		* By using TabSpec only we can able to setContent to the tab.
		* By using TabSpec setIndicator() we can set name to tab. */
	
		/** tid1 is firstTabSpec Id. Its used to access outside. */
		TabSpec detailsTab = tabHost.newTabSpec("tid1");
		 
		//Need to be the detailed chosen track view
		TabSpec trackTab = tabHost.newTabSpec("tid2");
		//TabSpec instructionsTab = tabHost.newTabSpec("tid3");

		Drawable detailsDrawable = getResources().getDrawable(R.drawable.alarm_symb );
	    View detailsTabIndicator = LayoutInflater.from(this).inflate(R.layout.main_tabhost_item, getTabWidget(), false);
	    ImageView detailsIcon = (ImageView) detailsTabIndicator.findViewById(R.id.icon);
	    detailsIcon.setImageDrawable(detailsDrawable);
	    detailsIcon.setBackgroundResource(R.drawable.tabhost_selector);
	    detailsIcon.setScaleType(ImageView.ScaleType.FIT_CENTER);
	    
	    
	    Intent detailsIntent = new Intent(this, RouteDetailsConfirmation.class);
	    detailsIntent.putExtra("arrivalHour", getIntent().getExtras().getString("arrivalHour"));
	    detailsIntent.putExtra("arrivalMinute", getIntent().getExtras().getString("arrivalMinute"));
	    detailsIntent.putExtra("hour", getIntent().getExtras().getString("hour"));
	    detailsIntent.putExtra("minute", getIntent().getExtras().getString("minute"));
	    detailsIntent.putExtra("origin", getIntent().getExtras().getString("origin"));
	    detailsIntent.putExtra("dest", getIntent().getExtras().getString("dest"));
	    detailsIntent.putExtra("tto", getIntent().getExtras().getString("tto"));
	    detailsIntent.putExtra("transport", getIntent().getExtras().getString("transport"));
	    detailsIntent.putExtra("repeat", getIntent().getExtras().getString("repeat"));
	    detailsIntent.putExtra("sortOfAlarm", getIntent().getExtras().getString("sortOfAlarm"));
	    detailsIntent.putExtra("label", getIntent().getExtras().getString("label"));
	    detailsIntent.putExtra("status", getIntent().getExtras().getString("status"));
	    detailsIntent.putExtra("daysIDS", getIntent().getExtras().getString("daysIDS"));
	    detailsIntent.putExtra("cancelDaysIDS", getIntent().getExtras().getString("cancelDaysIDS"));
		detailsIntent.putExtra("isNewAlarm", getIntent().getExtras().getBoolean("isNewAlarm"));
		detailsIntent.putExtra("id", getIntent().getExtras().getString("id"));
		detailsIntent.putExtra("index", getIntent().getExtras().getString("index"));	
		detailsIntent.putExtra("snoozeInterval", getIntent().getExtras().getString("snoozeInterval"));
		detailsIntent.putExtra("snoozeRepeat", getIntent().getExtras().getString("snoozeRepeat"));
		detailsIntent.putExtra("tune", getIntent().getExtras().getString("tune"));
		detailsIntent.putExtra("volume", getIntent().getExtras().getString("volume"));
		detailsIntent.putExtra("vibration", getIntent().getExtras().getString("vibration"));
		detailsIntent.putExtra("duration", getIntent().getExtras().getString("duration"));
		//detailsIntent.putExtra("durationNumeric", getIntent().getExtras().getString("durationNumeric"));		
		detailsIntent.putExtra("distance", getIntent().getExtras().getString("distance"));
		detailsIntent.putExtra("track", getIntent().getExtras().getSerializable("track"));

	    detailsTab.setContent(detailsIntent);
	    detailsTab.setIndicator(detailsTabIndicator);
		
	    //Need to create intent of detailed track (need to send it the current track - 
	    //make sure to put it as extra in confirmation function in set smart!!!
		Drawable trackDrawable = getResources().getDrawable( R.drawable.loc_grey);
	    View trackTabIndicator = LayoutInflater.from(this).inflate(R.layout.main_tabhost_item, getTabWidget(), false);
	    ImageView trackIcon = (ImageView) trackTabIndicator.findViewById(R.id.icon);
	    trackIcon.setImageDrawable(trackDrawable);
	    trackIcon.setBackgroundResource(R.drawable.tabhost_selector);
	    trackIcon.setScaleType(ImageView.ScaleType.FIT_CENTER);
	    
		Intent detailedTrackIntent = new Intent(this, DetailedTrack.class);	
		detailedTrackIntent.putExtra("track", getIntent().getExtras().getSerializable("track"));
		//isLink = true --> context of route details is confirmation! (used for removing set+cancel buttons)
		detailedTrackIntent.putExtra("isLink", true);
		
	    trackTab.setContent(detailedTrackIntent);
	    trackTab.setIndicator(trackTabIndicator);	
		
	    
	    //tabHost.addTab(instructionsTab);
	    tabHost.addTab(detailsTab);
	    tabHost.addTab(trackTab);
		

	    getTabHost().setOnTabChangedListener(new OnTabChangeListener() {
	        public void onTabChanged(String tabId)
	        {
	               View currentView = getTabHost().getCurrentView();
	               int currentTab = getTabHost().getCurrentTab();
	               
	               if(currentTab == 0)
	            	   currentTab = 1;
	               else
	            	   currentTab = 0;
	               
            	   Animation fadeIn = new AlphaAnimation(0, 1);
            	   fadeIn.setInterpolator(new DecelerateInterpolator()); //add this
            	   fadeIn.setDuration(1000);
	               
	               if (getTabHost().getCurrentTab() > currentTab)
	                   currentView.setAnimation(fadeIn);
	               else
	                   currentView.setAnimation(fadeIn);

	               
	        }
	   });
	    
    }
    
    
    public Animation inFromRightAnimation()
    {
        Animation inFromRight = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, +1.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        inFromRight.setDuration(240);
        inFromRight.setInterpolator(new AccelerateInterpolator());
        return inFromRight;
    }

    public Animation outToRightAnimation()
    {
        Animation outtoLeft = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, -1.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        outtoLeft.setDuration(240);
        outtoLeft.setInterpolator(new AccelerateInterpolator());
        return outtoLeft;
    }
 
	    
      
   @Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
	}

}
